//alert(opts.form_url);
/** 流程表单 */
var formStore = Ext.create('Ext.data.Store', {
    autoLoad: true,
    fields: ['FORM_ID', 'FORM_NAME'],
    proxy: {
        type: 'ajax',
        url : opts.form_url,
        reader: {
            type: 'json',
            root: 'forms'
        }
    },
    callback: function(records) { 
   		formStore.setValue(value); //显示与value对应的text
 	} 
});


var basePanel = Ext.create('Ext.form.Panel', {
	id: 'base',
	border: false,
	bodyStyle: {background:"#dfe7f4",padding:"10 0 0 20"},
	labelAlign: 'right',
	bodyPadding: 5,
	layout : 'column',
	fieldDefaults: {
		labelAlign: 'right',
		labelWidth: 90
 	},
	items:[{  
        columnWidth:.4,//指定列宽为容器宽度的50%  
        layout : 'form',
        height : 110 ,
        defaultType: 'textfield',
        frame : true,
        items : [{
			fieldLabel: '名&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;称',
			id: 'baseName',
			enableKeyEvents: true,
			listeners: {
				'keyup': function(e){
					if(opts.curXmlNode != null){
						//var nodeName = Ext.getCmp("baseName").getValue();
						opts.curXmlNode.setAttribute("name",e.getValue());
						opts.curNode.title=e.getValue();
						Ext.fly(opts.curNode.id).child('b').remove();
						Ext.fly(opts.curNode.id).insertHtml('beforeEnd','<b>'+e.getValue()+'</b>');
						
					} else {
						opts.xml.documentElement.setAttribute("name",e.getValue());
						
					}
					
				}
			}
		},{
			fieldLabel: '处&nbsp; 理&nbsp;类',
			id: 'assigHandler',
			enableKeyEvents: true,
			listeners: {
				'keyup': function(e){
					if(opts.curNode.nodeType!='start' || opts.curNode.nodeType!='end') {
						var nodes = opts.curXmlNode.getElementsByTagName('assignment-handler');
						nodes[0].setAttribute('expr', e.getValue());
					}
					
				}
			}
		},{
			xtype: 'combo',
			fieldLabel: '流程表单',
			id: 'formType',	
			emptyText: '请选择',
			border: false,
			width: 100,
			//readOnly : true,//是否只读 
			editable:false,
			displayField: 'FORM_NAME',
	    	valueField: 'FORM_ID',
	    	hiddenName:'FORM_NAME',
			store : formStore,
			listeners:{
				select:function(e){
					var _forms = e.getValue();//+'-'+r.getDisplayValue();
					if(opts.curXmlNode != null){					
						opts.curXmlNode.setAttribute("forms",_forms);
						
					} else {
						opts.xml.documentElement.setAttribute("forms",_forms);
						
					}
				}
			}
		}/*,{
			fieldLabel: 'x',
			id: 'nodeX',
			enableKeyEvents: true,
			listeners: {
				'keyup': function(e){
					if(opts.curNode.nodeType!='start' || opts.curNode.nodeType!='end') {
						var nodes = opts.curXmlNode.getElementsByTagName('assignment-handler');
						nodes[0].setAttribute('expr', e.getValue());
					}
					
				}
			}
		},{
			fieldLabel: 'y',
			id: 'nodeY',
			enableKeyEvents: true,
			listeners: {
				'keyup': function(e){
					if(opts.curNode.nodeType!='start' || opts.curNode.nodeType!='end') {
						var nodes = opts.curXmlNode.getElementsByTagName('assignment-handler');
						nodes[0].setAttribute('expr', e.getValue());
					}
					
				}
			}
		}*/]
    }, {//////////////////////////////////////////  
		columnWidth:.4,//指定列宽为容器宽度50%  
 		layout : 'form',
 		height : 110,
 		frame : true,
 		items : [{
	    	xtype:'checkboxgroup',
    		fieldLabel: '节点属性',
    		columns:2,
			items:[
    			{boxLabel:'动态跳转', name:'dynamicJump',id:'dynamicJump', 
    				listeners: {
    					afterrender:function(obj){
    						obj.getEl().dom.onclick = function () { 
    							if(Ext.getCmp("dynamicJump").getValue())
    								opts.curXmlNode.setAttribute("dynamicJump",1);
    							else
    								opts.curXmlNode.setAttribute("dynamicJump",0);
	                        };  
    					}
    				}	
    			},
    			{boxLabel:'动态分配', name:'dynamicSelect', id:'dynamicSelect',
    				listeners: {
    					afterrender:function(obj){
    						obj.getEl().dom.onclick = function () { 
    							if(Ext.getCmp("dynamicSelect").getValue())
    								opts.curXmlNode.setAttribute("dynamicSelect",1);
    							else
    								opts.curXmlNode.setAttribute("dynamicSelect",0);
	                        };  
    					}
    				}	
    			},
    			{boxLabel:'转办', name:'trunTodo', id:'trunTodo',
    				listeners: {
    					afterrender:function(obj){
    						obj.getEl().dom.onclick = function () { 
    							if(Ext.getCmp("trunTodo").getValue())
    								opts.curXmlNode.setAttribute("trunTodo",1);
    							else
    								opts.curXmlNode.setAttribute("trunTodo",0);
	                        };  
    					}
    				}	
    			},
    			{boxLabel:'附件文书', name:'flowAttr',id:'flowAttr',
    				listeners: {
    					afterrender:function(obj){
    						obj.getEl().dom.onclick = function () { 
    							if(Ext.getCmp("flowAttr").getValue())
    								opts.curXmlNode.setAttribute("flowAttr",1);
    							else
    								opts.curXmlNode.setAttribute("flowAttr",0);
	                        };  
    					}
    				}
    			},
    			{boxLabel:'撤销', name:'recover',id:'recover',
    				listeners: {
    					afterrender:function(obj){
    						obj.getEl().dom.onclick = function () { 
    							if(Ext.getCmp("recover").getValue())
    								opts.curXmlNode.setAttribute("recover",1);
    							else
    								opts.curXmlNode.setAttribute("recover",0);
	                        };  
    					}
    				}
    			}
			]
		},{
			fieldLabel: '审核时限',
			id: 'timeLimit',
			xtype:'numberfield',
			allowDecimals : false,//不允许输入小数  
            allowNegative : false,//不允许输入负数  
            nanText :'请输入有效的整数',//无效数字提示
			enableKeyEvents: true,
			maxValue : 100,//最大值  
         	minValue : 1,//最小值  
			//value:1,
//			minValue: 1,
			listeners: {
				'keyup': function(e){
					if(opts.curNode.nodeType!='start' && opts.curNode.nodeType!='end') {
						//var nodes = opts.curXmlNode.getElementsByTagName('timeLimit');
						
						 opts.curXmlNode.setAttribute('timeLimit', e.getValue());
					}
				}
			}
		}]
	},{columnWidth:.2, border:0}]
});

function setBase(){

	Ext.getCmp('paramCard').layout.setActiveItem(Ext.getCmp('base'));//显示面板
	Ext.getCmp("baseName").setValue("");
	Ext.getCmp("dynamicJump").setValue(false);
	Ext.getCmp("dynamicSelect").setValue(false);
	Ext.getCmp("trunTodo").setValue(false);
	Ext.getCmp("flowAttr").setValue(false);
	Ext.getCmp("recover").setValue(false);
	if(opts.curXmlNode != null){
		Ext.getCmp("baseName").setValue(opts.curXmlNode.getAttribute("name"));
		var nodes = opts.curXmlNode.getElementsByTagName('assignment-handler');
		Ext.getCmp("formType").select(formStore.findRecord('FORM_ID', opts.curXmlNode.getAttribute("forms")));
		Ext.getCmp("timeLimit").setValue(opts.curXmlNode.getAttribute("timeLimit"));//设置超时限制
		if(nodes.length>0){
			Ext.getCmp("assigHandler").setValue(nodes[0].getAttribute('expr'));
		}
		
		var dynamicJump = opts.curXmlNode.getAttribute("dynamicJump");
		if(dynamicJump=='1'){
			Ext.getCmp("dynamicJump").setValue(true);
		} 
		
		var dynamicSelect = opts.curXmlNode.getAttribute("dynamicSelect");
		if(dynamicSelect=='1'){
			Ext.getCmp("dynamicSelect").setValue(true);
		}
		
		var trunTodo = opts.curXmlNode.getAttribute("trunTodo");
		if(trunTodo=='1'){
			Ext.getCmp("trunTodo").setValue(true);
		}
		var flowAttr = opts.curXmlNode.getAttribute("flowAttr");
		if(flowAttr=='1'){
			Ext.getCmp("flowAttr").setValue(true);
		}
		var recover = opts.curXmlNode.getAttribute("recover");
		if(flowAttr=='1'){
			Ext.getCmp("recover").setValue(true);
		}
		
		
	} else {
	
		if(opts.xml != null){
			var processNode = opts.xml.documentElement;
			Ext.getCmp("baseName").setValue(processNode.getAttribute("name"));
			Ext.getCmp("assigHandler").setValue('');

		//	Ext.getCmp("formType").setValue(processNode.getAttribute("forms"));
			Ext.getCmp("formType").select(formStore.findRecord('FORM_ID', processNode.getAttribute("forms")));
			Ext.getCmp("timeLimit").setValue(processNode.getAttribute("timeLimit"));
			
		}

	}
	
}